<%-- 
    Document   : statistic
    Created on : Mar 14, 2011, 4:47:26 PM
    Author     : BAOBAO
--%>

<%@page import="java.text.DecimalFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@page import="com.myapp.biz.ReportBiz" %>
<%@page import="com.myapp.entities.Survey" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Survey statistic page</title>
    </head>
    <body>
        
         <%
                    HttpSession sess = request.getSession(true);
                    if (sess.getAttribute("username") == null) {
                        response.sendRedirect("login.jsp");
                    }
        %>
        <table style="border:1px solid #0e74a6; " align="center" >
            <tr bgcolor="#2792c5" style="color:#FFFFFF;font-weight:bold  ">
                <td>Id</td>
                <td>Survey name</td>
                <td align="center">Question</td>
                <td align="center" width="200">Answer</td>
                <td align="center" >Statistic(%)</td>
                
                
            </tr>
              <%
                ReportBiz rp=new ReportBiz();
                ArrayList<Survey> arr=new ArrayList<Survey>();
                     arr=rp.getSurveys(this.getServletContext().getRealPath("/"),"surveys.xml");
                     for (int i = 0; i < arr.size(); i++) {
                %>
                <tr bgcolor="#cccfff">
              
                <td><%=arr.get(i).getSurveyId()%></td>
                <td><%=arr.get(i).getSurveyName()%></td>
                <td><%=arr.get(i).getContent()%></td>

                <td align="justify" >
                 <%
                    for (int j = 0; j < arr.get(i).getAnsList().size(); j++) {
                %>
                 <%=(j+1)+") "+arr.get(i).getAnsList().get(j)%><br>
                  <%}%>
                </td>
                   
                <td align="justify" width="100">
                <%
                 
                for (int j = 0; j < arr.get(i).getStatistic().size(); j++) {
                   int numStatistic=Integer.parseInt(arr.get(i).getStatistic().get(j));
                   float total=Float.parseFloat(arr.get(i).getTotal());
                   DecimalFormat dec = new DecimalFormat("###.#");
                   String percent=dec.format((numStatistic/total)*100);
                %>
                    <%=numStatistic+" ~ ("+percent+" %)"%><br>
                  <%}%>

                </td>
                 
            </tr>
            <%}%>
            
        </table>
        
        <div align="center"><a href="index.jsp">Back to home</a></div>

    </body>
</html>
